package com.ruoyi.huanghefd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.huanghefd.domain.UserByRole;
import com.ruoyi.huanghefd.domain.Worksheet;
import com.ruoyi.huanghefd.mapper.UserByRoleMapper;
import com.ruoyi.huanghefd.service.UserByRoleService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author gnplum
 * @Date 2024/1/22 22:52
 * @PackageName:com.ruoyi.huanghefd.service.impl
 * @ClassName: UserByRoleServiceImpl
 * @Description: TODO
 * @Version 1.0
 */
@Service
public class UserByRoleServiceImpl extends ServiceImpl<UserByRoleMapper, UserByRole>
        implements UserByRoleService {

    @Resource
    UserByRoleMapper userByRoleMapper;

    @Override
    public PageBean queryUserByRoleByPage(String deptId, String userName, String roleKey, int pageNum, int pageSize) {
        PageBean pageBean = new PageBean();
        if (pageNum > 0 && pageSize > 0) {
            int totalRecord = userByRoleMapper.getUserByRoleNum(deptId, userName, roleKey);
            pageBean = new PageBean(pageNum, pageSize, totalRecord);

            //从该行开始拿数据
            int startIndex = (pageNum - 1) * pageSize;
            pageBean.setStartIndex(startIndex);
            pageBean.setCode(200);

            //数据集合
            List<UserByRole> userByRoleList = userByRoleMapper.queryUserByRoleByPage(deptId, userName, roleKey,startIndex, pageSize);
            pageBean.setList(userByRoleList);
            pageBean.setSuccessMsg("工作票人员查询成功！");
        } else {
            pageBean.setCode(500);
            pageBean.setFailMsg("工作票人员查询失败！");
        }
        return pageBean;
    }
}
